package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.pojo.entity.Notice;
import com.example.service.NoticeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 系统公告 controller 层
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Resource
    private NoticeService noticeService;

    @PostMapping("/add")
    public Result add(@RequestBody Notice notice) {
        this.noticeService.add(notice);
        return Result.success();
    }

    @GetMapping("/pageQuery")
    public Result pageQuery(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            Notice notice
    ) {
        PageResult<Notice> pageResult = this.noticeService.pageQuery(pageNum, pageSize, notice);
        return Result.success(pageResult);
    }

    @GetMapping("/query")
    public Result queryById(@RequestParam Integer id) {
        Notice notice = this.noticeService.queryById(id);
        return Result.success(notice);
    }

    @GetMapping("/query/all")
    public Result queryAll() {
        List<Notice> noticeList = this.noticeService.lambdaQuery().list();
        return Result.success(noticeList);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Notice notice) {
        this.noticeService.update(notice);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        this.noticeService.delete(id);
        return Result.success();
    }

    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        this.noticeService.deleteBatch(ids);
        return Result.success();
    }
}
